import { PageParams, PageResult } from "@/types/common"
import request from "@/utils/request"
import { DishListResult, DishResult, DishWithFlavorsData, DishWithFlavorsResult } from "@/types/dish";
/**
 * 菜品分页查询
 * @param params 
 * @returns 
 */
type DishPageParams = PageParams & {
  businessId?: number
  name?: string;
  categoryId?: number;
  status?: number;
};
export const getDishPageAPI = (params: DishPageParams) => {
  return request<PageResult<DishResult[]>>({
    method: 'GET',
    url: '/business/dish/page',
    params
  })
}
/**
 * 菜品起售、停售
 * @param status 
 * @returns 
 */
export const postDishStatusAPI = (status: number, id: number) => {
  return request({
    method: 'POST',
    url: `/business/dish/status/${status}`,
    params: { id }
  })
}
/**
 * 新增菜品
 * @param params 
 * @returns 
 */
export const addDishAPI = (params: DishWithFlavorsData) => {
  return request({
    method: 'POST',
    url: '/business/dish',
    data: params
  })
}
/**
 * 根据id查询菜品
 * @param id 
 * @returns 
 */
export const getDishAPI = (id: number) => {
  return request<DishWithFlavorsResult>({
    method: 'GET',
    url: `/business/dish/${id}`
  })
}
/**
 * 批量删除菜品
 * @param ids 
 * @returns 
 */
export const deleteDishAPI = (ids: string) => {
  return request({
    method: 'DELETE',
    url: '/business/dish',
    params: { ids }
  })
}
/**
 * 修改菜品
 * @param params 
 * @returns 
 */
export const putDishAPI = (params: DishWithFlavorsData) => {
  return request({
    method: 'PUT',
    url: '/business/dish',
    data: params
  })
}
/**
 * 根据分类id查询菜品
 * @param categoryId 
 * @returns 
 */
export const getDishListAPI = (categoryId: number) => {
  return request<DishListResult[]>({
    method: 'GET',
    url: '/business/dish/list',
    params: { categoryId }
  })
}